//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Copyright 2012 Microsoft Corporation. All Rights Reserved
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.   
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

namespace Preflight.Model
{
    using System;
    using System.Text;

    /// <summary>
    /// Preflight Engine Options
    /// </summary>
    public sealed class PreflightOptions
    {
        /// <summary>
        /// Default Constructor
        /// </summary>
        public PreflightOptions()
        {
            this.SequentialMode = false;
            this.EnableResultCaching = false;
            this.ResultCachingDuration = TimeSpan.FromMinutes(5);
            this.VerificationTimeout = TimeSpan.FromMinutes(1);
            this.MaximumNumberOfConcurrentRequests = 5;
            this.MessagingLevel = MessagingLevel.All;
        }

        /// <summary>
        /// Gets or sets whether Preflight will run the verifications sequentially in a synchronous fashion
        /// or the verifications will run in parallel
        /// </summary>
        /// <remarks>
        /// This is false by default
        /// </remarks>
        public bool SequentialMode { get; set; }

        /// <summary>
        /// Gets or sets whether Preflight should cache results for a certain period of time
        /// to prevent verifications from getting executed too many times
        /// </summary>
        /// <remarks>
        /// This is set to false by default.
        /// </remarks>
        public bool EnableResultCaching { get; set; }

        /// <summary>
        /// Gets or sets the duration of result caching. Only used when result caching is enabled
        /// </summary>
        /// <remarks>
        /// This is set to 5 minutes by default.
        /// </remarks>
        public TimeSpan ResultCachingDuration { get; set; }

        /// <summary>
        /// Gets or sets maximum allowed time for a verification to complete. Otherwise the task will be cancelled.
        /// </summary>
        /// <remarks>
        /// This is set to 1 minute by default.
        /// </remarks>
        public TimeSpan VerificationTimeout { get; set; }

        /// <summary>
        /// Gets or sets the maximum number of concurrent requests the engine will handle.
        /// Once the number of concurrent requests is reached, the request will be queued.
        /// </summary>
        /// <remarks>
        /// This is set to 5 by default.
        /// </remarks>
        public int MaximumNumberOfConcurrentRequests { get; set; }

        /// <summary>
        /// Gets or Sets the level of messaging included in results
        /// </summary>
        /// <remarks>
        /// By default this is set to all (info, warning and error)
        /// </remarks>
        public MessagingLevel MessagingLevel { get; set; }

        public override string ToString()
        {
            var builder = new StringBuilder();
            builder.Append("Preflight-Options:");
            builder.AppendFormat(" [SequentialMode = {0}]", this.SequentialMode);
            builder.AppendFormat(" [EnableResultCaching = {0}]", this.EnableResultCaching);
            builder.AppendFormat(" [MaximumNumberOfConcurrentRequests = {0}]", this.MaximumNumberOfConcurrentRequests);
            builder.AppendFormat(" [ResultCachingDuration = {0}]", this.ResultCachingDuration);
            builder.AppendFormat(" [VerificationTimeout = {0}]", this.VerificationTimeout);
            builder.AppendFormat(" [MessagingLevel = {0}]", this.MessagingLevel);
            return builder.ToString();
        }
    }
}